from . import db
from datetime import datetime

class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(5), unique=True, nullable=False)
    password_hash = db.Column(db.String(255), nullable=False)
    created_at = db.Column(db.DateTime, server_default=db.func.now())
    updated_at = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())
    snake_score = db.Column(db.Integer, default=0)
    two_score = db.Column(db.Integer, default=0)
    plane_score = db.Column(db.Integer, default=0)
    mario_score = db.Column(db.Integer, default=0)
    eat_score = db.Column(db.Integer, default=0)
    avatar_url = db.Column(db.String(255), default='/static/avatars/default.png')
    manage = db.Column(db.Integer, default=0)

class Message(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    area = db.Column(db.String(50), nullable=False)
    likes = db.Column(db.Integer, default=0)

class Zone(db.Model):
    __tablename__ = 'zones'
    key = db.Column(db.String(32), primary_key=True)     # 图片名或自定义key
    title = db.Column(db.String(64))
    desc = db.Column(db.String(255))
    image = db.Column(db.String(255))   # 图片url或路径